from django.shortcuts import render
from django.http import HttpResponse
from django.contrib.auth.models import User, Group, ContentType, Permission
from django.contrib.auth import authenticate


def index(request):
    # user = User.objects.create_user(username="mingda", email="mingda@qq.com", password="11111111")
    # super_user = User.objects.create_superuser(username="admin", email="admin@qq.com", password="admin111")
    # user = User.objects.get(pk=1)
    # user.set_password("22222222")
    # user.save()
    # 验证用户名密码
    username = "mingda"
    password = "22222222"
    user = authenticate(request, username=username, password=password)
    if user:
        print("success")
    else:
        print("wrong")
    return HttpResponse('hello')


def op_group(request):
    group = Group.objects.create(name="买家")
    content_type = ContentType.objects.get_for_model(User)
    permission = Permission.objects.filter(content_type=content_type)
    group.permissions.set(permission)
    group.save()

